// src/controller/user.ts

import { Controller, Get, Inject, Query } from '@midwayjs/decorator';
import { User } from '../../interface';
import { Context } from '@midwayjs/koa';

@Controller('/api/controller/param/query')
export class UserController {
  @Inject()
  ctx: Context;

  /**
   * 示例：从装饰器获取
   * @param id
   */
  @Get('/testGetParam')
  async testAtQuery(@Query('id') id: string): Promise<User> {
    // xxxx
    console.info('id : ', id);
    return {
      id: 1,
      name: 'testAtQuery',
      age: 1,
    };
  }

  @Get('/testGetParamFromQueryData')
  async testAtQueryData(@Query() queryData): Promise<User> {
    // xxxx
    console.info('queryData : ', queryData);
    return {
      id: 1,
      name: 'testAtQuery',
      age: 1,
    };
  }

  /**
   * 示例：从 API 获取
   */
  @Get('/testGetParamFromApiWithCtx')
  async getUser(): Promise<User> {
    const query = this.ctx.query;
    console.log('query:', query);
    return {
      id: 1,
      name: 'testAtQuery',
      age: 1,
    };
  }
}
